#include <iostream>
#include "gtest/gtest.h"

int add(int a, int b) {
    return a + b;
}

bool isTrue() {
    return true;
}

TEST(add, zero) {
    EXPECT_EQ(0, add(0, 0)) << "yes";
}

TEST(add, positive_number) {
    EXPECT_EQ(3, add(1, 2));
}

TEST(add, negative_number) {
    EXPECT_EQ(-3, add(-1, -2));
}

// 条件判断
TEST(condition, condition) {
    ASSERT_TRUE(1);  // 判断条件是否为真
    ASSERT_FALSE(0); // 判断条件是否为假

    EXPECT_TRUE(1);  // 判断条件是否为真
    EXPECT_FALSE(0); // 判断条件是否为假
}

// 数值比较
TEST(valueCompare, valueCompare) {
    ASSERT_EQ(1, 1); // 判断是否相等
    ASSERT_NE(1, 2); // 判断是否不相等
    ASSERT_LT(1, 2); // 判断是否小于
    ASSERT_LE(1, 3); // 判断是否小于等于
    ASSERT_GT(3, 1); // 判断是否大于
    ASSERT_GE(3, 1); // 判断是否大于等于

    EXPECT_EQ(1, 1); // 判断是否相等
    EXPECT_NE(1, 2); // 判断是否不相等
    EXPECT_LT(1, 2); // 判断是否小于
    EXPECT_LE(1, 2); // 判断是否小于等于
    EXPECT_GT(3, 1); // 判断是否大于
    EXPECT_GE(3, 1); // 判断是否大于等于
}

//字符串比较
TEST(stringCompare, stringCompare) {
    ASSERT_STREQ("hello", "hello");
    ASSERT_STRNE("HELLO", "HELLO2");
    ASSERT_STRCASEEQ("HELLO", "hello");
    ASSERT_STRCASENE("HELLO", "hELLO2");

    EXPECT_STREQ("hello","hello"); // 判断字符串是否相等
    EXPECT_STRNE("hello","hello2"); // 判断字符串是否不相等
    EXPECT_STRCASEEQ("hello","HELLO"); // 判断字符串是否相等，忽视大小写
    EXPECT_STRCASENE("hello","HELLO2"); // 判断字符串是否不相等，忽视大小写
}

bool pred1(int val) {
    return val == 3;
}

// 自定义谓词函数，检查字符串长度是否大于某个值
bool pred2(const std::string& str, size_t length) {
    if (str.length() <= length) {
        GTEST_NONFATAL_FAILURE_("String length is not greater than specified length");
        return false;
    }
    return true;
}

bool pred3(int val, int val2, int val3) {
    return val == val2 + val3;
}

bool pred4(int val, int val2, int val3, int val4) {
    return val == val2 + val3 + val4;
}

bool pred5(int val, int val2, int val3, int val4, int val5) {
    return val == val2 + val3 + val4 + val5;
}

// 谓词断言
TEST(predicate, predicate) {
    std::string s = "hello";
    EXPECT_PRED1(pred1, 3);
    EXPECT_PRED2(pred2, s, 3);
    EXPECT_PRED2(pred2, s, 10);
    EXPECT_PRED3(pred3,2,1,1);
    EXPECT_PRED4(pred4,3,1,1,1);
    EXPECT_PRED5(pred5,4,1,1,1,1);

    ASSERT_PRED1(pred1,3);
    ASSERT_PRED2(pred2,s,3);
    ASSERT_PRED3(pred3,2,1,1);
    ASSERT_PRED4(pred4,3,1,1,1);
    ASSERT_PRED5(pred5,4,1,1,1,1);
}

int main(int argc, char *argv[]) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}